#include "templates.h"
#include "Utils.h"

#include <opencv2\highgui\highgui.hpp>

//------------------------------------------------------------------------------------------
TemplateMatching::Templates::Templates(const std::string &folder)
{
	std::vector<std::string> files;
	
	if(!Utils::GetFilesInDirectory(folder,"*.bmp",files))
	{
		throw std::exception();
	}
	int maxWidth = 0;
	int maxHeight = 0;
	for(int i = 0; i < static_cast<int>(files.size());i++)
	{		
		char ch;
		int num;
		
		const std::string filename = Utils::GetFileNameWithoutExtension(files[i]);

		this->templateImages.push_back(cv::imread(files[i],0));
		this->templateChars += filename[0];
		

		maxWidth  = std::max(maxWidth ,this->templateImages.rbegin()->size().width );
		maxHeight = std::max(maxHeight,this->templateImages.rbegin()->size().height);

		//validPatternsFound++;
	}


	this->maxTemplateSize = cv::Size(maxWidth,maxHeight);
	if(templateImages.size()!=this->templateChars.size())
		throw std::range_error("unknown error loading templates");
	


}
//------------------------------------------------------------------------------------------